package com.nightpiter.controller;

import java.io.File;
import java.util.ArrayList;
import java.util.List;



import com.nightpiter.NightPiter;
import com.nightpiter.R;

public class FileLister {
	private NightPiter context;
	
	public FileLister(NightPiter  context){
		this.context = context;		
	}

	private static final String EMPTYDIR = "<Directory is Empty>";
	private List<String> filesList = new ArrayList<String>();

	public List<String> getFilesList(){		
		filesList.clear();
		File dir = new File(context.getString(R.string.maps_dir));
		if (!dir.exists()) {
			dir.mkdir();
		}
		for (File file : dir.listFiles()) {
			String fn = file.getName();
			if (fn.endsWith(context.getString(R.string.maps_extension))) {
				filesList.add(fn);
			}
		}
		if (filesList.size() == 0) {
			filesList.add(EMPTYDIR);
		}
		return filesList;
	}
	
	
	public String getFileName(int id){
		return filesList.get(id);
	}
}
